package com.longtengyuyun.product;

import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.KafkaAdminClient;
import org.apache.kafka.clients.admin.ListTopicsResult;
import org.apache.kafka.clients.admin.NewTopic;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.internals.Topic;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * @author ZhaoYunLong
 * @date 2022/3/11
 * @description
 */
public class KafkaProduct {


    public static void main(String[] args) {
        //        创建topic
        Properties props = new Properties();
        props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "10.10.60.119:9092,10.10.60.120:9092,10.10.60.121:9092");
        props.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        props.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        props.setProperty(ProducerConfig.PARTITIONER_CLASS_CONFIG)

        KafkaProducer<String, String> kafkaProduct = new KafkaProducer<>(props);
        for (int i = 0; i<10 ; i++) {
            ProducerRecord topic_zyl = new ProducerRecord("topic_zyl", "zyl" + i, "zyl_value" + i);
            kafkaProduct.send(topic_zyl);
            kafkaProduct.sendOffsetsToTransaction();
        }
    }
}
